<html>
<body>
<h1>hello word!!!</h1>
<p>this is a html page</p>
<script>
    function getWebSocketUrl() {
        var protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
        var host = window.location.host;
        return protocol + '127.0.0.1:8888' + '/webSocket';
    }
    var WebSocketUrl = getWebSocketUrl();
    var ws = new WebSocket(WebSocketUrl);
    ws.onmessage = function(event) {
        console.log('收到消息：', event.data);
        // 将 JSON 字符串解析为 JavaScript 对象
        var jsonData = JSON.parse(event.data);

    };

    // 监听错误事件
    ws.onerror = function(error) {
        console.error('WebSocket Error:', error);
    };
    ws.onopen = function(masg) {
        console.log('发送信息:',1111);
        ws.send(1111)
    };
</script>
</body>
</html>